
<title>帐号信息</title>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>帐号信息</cite></a>
  </div>
</div>
  
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
          <div class="layui-card-header">帐号信息</div>
        <div class="layui-card-body" pad15>          
            <div class="layui-form" lay-filter="">
                <input type="hidden" name="id" value="0" />
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="nickname" value="" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phonenumber" value="" lay-verify="" readonly autocomplete="off" placeholder="" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">不可修改，用于登录唯一标识</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-inline">
                        <input type="text" name="email" value="" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                    </div>
                </div>
            </div>          
        </div>
      </div>
    </div>
  </div>
</div>

<script>
    layui.use('set', layui.factory('set')).use('admin',function () {
        var $ = layui.$
            , layer = layui.layer
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form;

        console.log(setter);

        //ajax异步获取当前登录用户信息
        admin.req({
            url: setter.baseConfig.apiHost + '/api/user/getloginuserinfo' //实际使用请改成服务端真实接口
            , type: 'post'
            , contentType: "application/json"
            //, data: JSON.stringify(obj.field)
            , beforeSend: function (xhr) {
                xhr.setRequestHeader("Authorization", 'Bearer '+layui.data(setter.tableName)[setter.request.tokenName]);
            }
            , done: function (res) {
                if (res.errorCode != '00000') {
                    layer.msg(res.errorMessage, {
                        offset: '15px'
                        , icon: 2
                        , time: 3000
                    });

                    return false;
                }

                //给表单控件赋值
                $('input[name="id"]').val(res.data.id);
                $('input[name="nickname"]').val(res.data.nickName);
                $('input[name="phonenumber"]').val(res.data.phoneNumber);
                $('input[name="email"]').val(res.data.email);
            }
        });

    });
</script>